<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" :labelWidth="90" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <!-- :params="fetchParams"
      :fetchapi="fetchApi"
      :datakey="'rows'" -->
    <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="false"
      :isToperInfo="false"
      :dataSource="tableDataList"
      :onColumnsChange="columns => (this.columns = columns)"
      :isMemoryPagination="true"
      columnsRef="zjwxlsOEMTable"
    >
    </FilterTable>
    <div style="height:53px"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer()">返 回</el-button>
    </div>

    <BaseDialog :visible.sync="settlementVisible" title="结算明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <settlement :getdata="settlementdata" @close="closeSpop"></settlement>
    </BaseDialog>
    <BaseDialog :visible.sync="jobVisible" title="维修明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" @close="close">
      <jobdetail :getdata="settlementdata" @close="closeJpop"></jobdetail>
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import jobdetail from './Detailed/jobdetailTow.vue';
import settlement from './Detailed/Settlement.vue';
// import oemSettlement from './Detailed/oemSettlement.vue';
// import jobDetail from './Detailed/oemjobdetail.vue';

import { getoemList, getfindAllRepairType } from '@/api/repair/business/customer/history';
import { getDealerUser } from '@/api/customerRepair/customerComplaint/customerComplaintReception';

export default {
  name: 'wxlsoem',
  components: {
    jobdetail,
    settlement
  },
  mixins: [dictionary],
  props: ['setdata'],
  data() {
    this.BaseTable = null;
    return {
      fetchApi: getoemList,
      fetchParams: { VIN: this.setdata.VIN, xhrAbort: true },
      topFilterList: this.createTopFilterList(),
      columns: this.createTable(),
      settlementdata: { RO_NO: '' },
      jobdata: {},
      jobVisible: false,
      settlementVisible: false,
      list: [],
      tableDataList: []
    };
  },
  created() {},
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.changeHandle();
    // this.getEmp();
  },
  methods: {
    createTopFilterList() {
      return [
        // {
        //   type: 'RANGE_DATE',
        //   label: '开单日期',
        //   fieldName: 'beginDate|endDate'
        // }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.jobdetailFun(props)}>
                  维修明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '工单号',
          dataIndex: 'RoNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'LicenseNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '工单类型',
        //   dataIndex: 'ro_type',
        //   sorter: true,
        //   filter: true,
        //   hidden: true,
        //   render: props => {
        //     return <span>{this.createDictText(props.row.ro_type, '8068')}</span>;
        //   }
        // },
        {
          title: '维修类型',
          dataIndex: 'RoType',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '进厂里程',
          dataIndex: 'EnterMileage',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.EnterMileage * 10000}</span>;
          }
        },
        {
          title: '开单日期',
          width: 150,
          dataIndex: 'StartDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '服务顾问',
        //   dataIndex: 'ServiceConsultant',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '结算状态',
          dataIndex: 'BalanceStatus',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.BalanceStatus === '1' ? '结清' : props.row.BalanceStatus === '2' ? '欠账' : '未结算'}</span>;
          }
        }
      ];
    },
    closeDrawer() {
      this.$emit('close', false);
    },
    // 查看结算单
    // settlementFun(data) {
    //   console.log(data.row.RoNo);
    //   this.settlementdata = { RO_NO: data.row.RoNo };
    //   this.settlementVisible = true;
    // },
    // 维修明细
    jobdetailFun(data) {
      console.log('点击维修明细行项', data.row);
      this.settlementdata = data.row;
      console.log('data', data);
      this.jobVisible = true;
    },
    // // 查看工单
    // jobFun(data) {
    //   this.settlementdata = { RO_NO: data.row.ro_no };
    //   this.jobVisible = true;
    // },
    closeSpop(val) {
      this.settlementVisible = false;
    },
    close() {
      this.fetchParams = Object.assign({}, { xhrAbort: false, vin: this.setdata.VIN });
    },
    closeJpop(val) {
      this.jobVisible = false;
      this.fetchParams = Object.assign({}, val, { xhrAbort: false, vin: this.setdata.VIN });
    },
    // 搜索
    changeHandle(val) {
      if (!this.setdata.VIN) {
        this.$notify.warning({ title: '提示信息', message: '请输入VIN' });
      } else {
        // this.fetchParams = Object.assign({}, val, { xhrAbort: false, vin: this.setdata.VIN });
        this.queryTableDataList(val);
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 获取全部员工
    // async getEmp() {
    //   const res = await getDealerUser();
    //   let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    //   this.columns.find(item => item.dataIndex === 'service_advisor').editItems = empList; // 服务顾问
    // }
    async queryTableDataList(data = {}) {
      try {
        this.$refs.table.START_LOADING();
        let res = await getoemList({ ...data, vin: this.setdata.VIN });
        if (res.resultCode == 200) {
          this.tableDataList = res.data.rows;
        }
      } catch (err) {
        console.log(err, '获取oem维修历史失败');
      } finally {
        this.$refs.table.STOP_LOADING();
      }
    }
  }
};
</script>
